﻿@{
    Layout = "~/Views/Shared/_Form.cshtml";
}
@model Raffles.OA.Data.Department 
<link href="~/Content/plugin/ztree/css/metroStyle/metroStyle.min.css" rel="stylesheet" />
<link href="~/Content/plugin/ztree/core/treeSelect.css" rel="stylesheet" />
<form class="form-horizontal m" role="form">
    <div class="form-group">
        <label class="col-sm-3 control-label">上级部门</label>
        <div class="col-sm-9">
            <div class="treeSelect"></div>
            @Html.Hidden("TreeId", Model.ParentId)
        </div>
    </div> 
    <div class="form-group">
        <label class="col-sm-3 control-label">部门名称<font class="red">*</font></label>
        <div class="col-sm-9">
            @Html.TextBoxFor(model => model.Name, new { @class = "form-control required", @placeholder = "请输入部门名称" })
        </div>
    </div>  
    <div class="form-group">
        <label class="col-sm-3 control-label">显示顺序<font class="red">*</font></label>
        <div class="col-sm-9">
            @Html.TextBoxFor(model => model.DisplayOrder, new { @class = "form-control required", @type = "number", @min = "0", @placeholder = "请输入显示顺序" })
        </div>
    </div>
</form>
<script src="~/Content/plugin/ztree/js/jquery.ztree.all.min.js"></script>
<script src="~/Content/plugin/ztree/core/treeSelect.js"></script>
<script>
    var id = frame.request("id");
    $(function () {
        frame.ajax({
            url: '@Url.Content("/Manage/Department/GetDepartTreeSelect")',
            type: "get",
            success: function (result) {
                if (result.success) {
                    $(".treeSelect").treeSelect({
                        data: result.data,
                        placeholder: "请选择上级部门",
                        inputId: "txt" 
                    })
                    var zTreeObj = $.fn.zTree.getZTreeObj("_treeDomtxt"); 
                    //zTreeObj.expandAll(true);
                    if (@Model.Id> 0 &&@Model.ParentId> 0) { 
                        zTreeObj.selectNode(zTreeObj.getNodeByParam("id", @Model.ParentId));
                        $('#txt').val(zTreeObj.getNodeByParam("id", @Model.ParentId).name);
                    }
                   
                }
            }
        });  
    })
    function saveForm() { 
        if ($('form').validate().form()) { 
            frame.ajax({
                url: '@Url.Content("/Manage/Department/SaveForm")',
                type: "post",
                data: $('form').formSerialize(),
                success: function (obj) {
                    if (obj.success) {
                        frame.msgSuccess(obj.message); 
                        parent.location.reload();
                        frame.closeDialog(); 
                    }
                    else {
                        frame.msgError(obj.message);
                    }
                }
            });
        }
    }
</script>